	function bsacalc(unitchoice,sex,height,weight){

	var bsa=0;
	var lbw=0;
	var bmi=0;
	var ibw=0;
//convert to metric
if (!unitchoice){
height=height*2.54;
weight=weight*0.45359237;
}

//height from cm to m
height=height/100;
// Dubois formula
// BSA=0.20247 x Height(m)^0.725 x Weight(kg)^0.425
bsa=0.20247 * Math.pow(height,0.725) * Math.pow(weight,0.425);
//round off 2 dec places
bsa=Math.round(bsa*100)/100;		

//James
//Lean Body Weight (men) = (1.10 x Weight(kg)) - 128 ( Weight2/(100 x Height(m))2)
//Lean Body Weight (women) = (1.07 x Weight(kg)) - 148 ( Weight2/(100 x Height(m))2) 
//Boer
//LBW Male(0.407 * (body weight in kilograms)) + (26.7 * (height in meters)) - 19.2
// LBW Female (0.252 * (body weight in kilograms)) + (47.3 * (height in meters)) - 48.3

if (sex==1){
//lbw=(1.1*weight) - 128*( Math.pow(weight,2)/Math.pow(100*height,2));
lbw=(0.407*weight) + (26.7*height) - 19.2;
}

if (sex==0){
//lbw=(1.07*weight) - 148*( Math.pow(weight,2)/Math.pow(100*height,2));
lbw=(0.252*weight) + (47.3*height) - 48.3;
}

lbw=Math.round(lbw);

//BMI
bmi=weight/Math.pow(height,2);
bmi=Math.round(bmi*100)/100;

//IBW
ibwheight=height*100/2.54;
// male
if ((sex==1)&&(ibwheight>60)) {
ibw = 51.65 + 1.85*(ibwheight-60);
}
// female
if ((sex==0)&&(ibwheight>60)) {
ibw = 48.67 + 1.65*(ibwheight-60);
}
ibw=Math.round(ibw);

//convert back to SI
//if (!unitchoice){
//height=height/2.54;
//weight=weight/0.45359237;
weight=Math.round(weight);
//}


height=height*100;

return {
			 bsa:bsa,
			 height:height,
			 weight:weight,
			 lbw:lbw,
			 bmi:bmi,
			 ibw:ibw
	};		 
}




function ref(){
// display reference

var bmiref="BMI: Calle EE. NEJM 1999;341:1097-1105";
var ibwref="IBW: Robinson JD et al. Am J Hosp Pharm. 1983 Jun;40(6):1016-9.";
var lbwref="LBW: Boer P. Estimated lean body mass as an index for normalization of body fluid volumes in humans. Am J Physiol. 1984; 247: F632-F636."
return "BSA: DuBois D DuBois EF: A formula to estimate the approximate surface area if height and weight be known. Arch Int Med 1916 17:863-71" +"<br/>" + bmiref + "<br/>" + ibwref + "<br/>" + lbwref;
}

function help() {
	return "Interpretation of BMI<br />Adult values:" + "<br />< 18.5 = Underweight" + "<br />18.5-24.9 = Normal"+ "<br />25-29.9 = Overweight"+ "<br />>30 = Obese"; 
}